package com.autcar.training.controller;

import com.autcar.training.entity.Customer;
import com.autcar.training.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.controller
 * @ClassName: CustomerController
 * @Author: YHHHH
 * @Description: 员工控制类
 * @Date: 2020/8/29 9:44
 * @Version: 1.0
 */
@RestController
public class CustomerController {


    @Autowired
    private CustomerService customerService;


    /*
    查询所有的客户
     */
    @GetMapping("/customerAll")
    public List<Customer> customerList(){
        List<Customer> customerList = customerService.findAllCustomer();
        return customerList;
    }
    /*
    增加一个客户
     */
    @PostMapping("/customerAdd")
    public List<Customer> customerAdd(@RequestBody Customer customer){
        int i = customerService.addCustomer(customer);
        return null;
    }
    /*
    通过id删除客户
     */
    @PostMapping("/customerDelete/{id}")
    public String customerDeleteById(@PathVariable("id")Integer id){
        customerService.deleteCustomer(id);

        return null;
    }

    /*
    根据名字模糊查询客户
     */
    @GetMapping("/customerSelectByName/{name}")
    public List selectByName(@PathVariable("name")String name){
        List<Customer> selectByName = customerService.selectByName(name);
        return selectByName;
    }

    /*
    根据ID查询客户
     */
    @GetMapping("/customerSelectById/{id}")
    public Customer selectById(@PathVariable("id") Integer id){
        Customer customer = customerService.selectById(id);
        return customer;
    }

    @RequestMapping("/updateCustomer")
    public String updateCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return null;
    }


    @PostMapping("/updateMember")
    public Customer EditCustomer(@RequestBody Customer customer){
        customerService.updateCustomer(customer);
        return null;
    }
}
